package com.tanhua.server.controller;

import com.tanhua.server.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/smallVideos")
public class VideoController {

    @Autowired
    private VideoService videoService;
    /**
     * 小视频-发布小视频
     * POST /smallVideos
     *
     * @param videoThumbnail 视频的封面图
     * @param videoFile      视频文件
     */

    @PostMapping
    public ResponseEntity saveVideo(MultipartFile videoThumbnail,MultipartFile  videoFile) throws IOException {
        return videoService.saveVideo(videoThumbnail,videoFile);
    }

    @GetMapping
    public ResponseEntity findVideoList(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int pagesize) {
        if (page < 1) {
            page = 1;
        }
        return videoService.findVideoList(page, pagesize);
    }

    @PostMapping("/{uid}/userFocus")
    public  ResponseEntity focus(@PathVariable("uid") Long targetUserId) {
        return videoService.focus(targetUserId);
    }

    @PostMapping("/{uid}/userUnFocus")
    public  ResponseEntity unFocus(@PathVariable("uid") Long targetUserId) {
        return videoService.unFocus(targetUserId);
    }
}
